<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\Updateversion;

class UpdateController extends Controller
{
    public function getLatestVersion(Request $request)
    {
    	$version_param = $request->input("version","");
    	if(empty($version_param)) {
    		return response()->json(['message' =>'版本参数错误','code' => 400]);
    	}
    	$version = Updateversion::orderBy('update_time', 'DESC')->first();
    	$version = json_decode(json_encode($version), true);

    	$returnData = array();
    	if($version['compare_version'] > $version_param) {
    		$returnData['version'] = $version['version'];
    		$returnData['compare_version'] = $version['compare_version'];
    		$returnData['down_url'] = $version['down_url'];
    		$returnData['update_content'] = $version['update_content'];
    		$returnData['update_content'] = str_replace("\r\n","\n",$returnData['update_content']);
            $returnData['apk_check_code'] = $version['apk_check_code'];
    		return response()->json(['data' => $returnData,'message' =>'','code' => 200]);
    	} else {
    		return response()->json(['message' =>'无版本更新','code' => 200]);
    	}
    }
}
